package spe.ui.menu.popup.actionprovider;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.navigator.CommonActionProvider;
import org.eclipse.ui.navigator.ICommonActionConstants;
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;

public class DoubleClickActionProvider extends CommonActionProvider 
{
	private IWorkbenchPage page = null;
	
	@Override
	public void init(ICommonActionExtensionSite aSite)
	{
		super.init(aSite);
		IWorkbenchWindow window;
		if(aSite.getViewSite() instanceof ICommonViewerWorkbenchSite)
		{
			window = ((ICommonViewerWorkbenchSite)aSite.getViewSite()).getWorkbenchWindow();
			page = window.getActivePage();
		}
	}
	
	@Override
	public void fillActionBars(IActionBars actionBars)
	{
		super.fillActionBars(actionBars);
		
		IStructuredSelection selection = (IStructuredSelection)getContext().getSelection();
		
		//re-target the double-click open action.
		actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, new MyOpenAction(selection.getFirstElement(), page));
	}
}
